package com.aaa.sbms.service;

import com.aaa.sbms.dao.TrainVideoDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @FileName:TrainVideoServiceImpl
 * @Description:
 * @Author :99728
 * @Date: 2020/6/22 16:43
 * @Version:1.0.0
 */
@Service
public class TrainVideoServiceImpl implements TrainVideoService {
    @Autowired
    private TrainVideoDao trainVideoDao;
    public Map getPage(Map map) {
        map.put("begin",(Integer.valueOf(map.get("pageNo")+"")-1)* Integer.valueOf(map.get("pageSize")+""));
        Integer pageSize = Integer.valueOf(map.get("pageSize").toString());
        map.put("pageSize",pageSize);
        //调用dao获取数据
        List<Map> page = trainVideoDao.getPage(map);
        int total = trainVideoDao.getPageCount(map);
        //合并
        Map resultMap = new HashMap();
        resultMap.put("page",page);
        resultMap.put("total",total);
        return resultMap;
    }

    @Override
    public Map oneList(int videoid) {
        Map onelist = trainVideoDao.onelist(videoid);
        HashMap<Object, Object> resultMap = new HashMap<>();
        String sshotpath=null;
        if ((onelist.get("sshotpath")==null)||onelist.get("sshotpath")==""){
            resultMap.put("path","201");
        }else {
            sshotpath = onelist.get("sshotpath").toString();
            resultMap.put("path",sshotpath);
        }
        resultMap.put("list",onelist);
        return resultMap;
    }

    @Override
    public Map getCourseName(Map map) {
        Map result = new HashMap();
        result.put("list",trainVideoDao.getCourseName(map));
        return result;
    }

    @Override
    public int add(Map map) {
        return trainVideoDao.add(map);
    }

    @Override
    public int delete(int videoid) {
        return trainVideoDao.delete(videoid);
    }

    @Override
    public int update(Map map) {
        return trainVideoDao.update(map);
    }


}
